using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Collections.Generic;
using System.ComponentModel;
using Crainiate.Data.Persistence.Providers;

namespace Crainiate.Data.Persistence.Providers.Remoting
{
	//Follows the singleton pattern to store state for remoting 
	sealed public class RemoteProviderConfiguration 
	{
		//Singleton instance
		public static readonly RemoteProviderConfiguration Instance = new RemoteProviderConfiguration();

		//Property variables
        private Dictionary<string, Context> _contexts;
        
		#region Interface

		//Constructors
        private RemoteProviderConfiguration()
		{
            _contexts = new Dictionary<string, Context>();
		}

        //Methods
        public void AddContext(string name, Context context)
        {
            if (_contexts.ContainsKey(name)) throw new RemotingProviderException("A context with that name has already been added to the remote context collection.");
            _contexts.Add(name, context);
        }

        public Context ResolveContext(RemoteContext context)
        {
            if (!_contexts.ContainsKey(context.Name)) throw new RemotingProviderException("A matching context could not be found for the remote context supplied.");
            return _contexts[context.Name];
        }

        public void RemoveContext(string name)
        {
            if (_contexts.ContainsKey(name)) _contexts.Remove(name);
        }

		#endregion

		#region Implementation

		#endregion
	}
}
